package com.ops.controller;

import com.ops.entity.Hospital;
import com.ops.entity.Report;
import com.ops.service.HospitalService;
import com.ops.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class ReportListController {
    
    @Autowired
    private ReportService reportService;
    
    @Autowired
    private HospitalService hospitalService;
    
    @GetMapping("/report-list")
    public String showReportList(Model model) {
        // 获取医院列表
        List<Hospital> hospitals = hospitalService.getAllHospitals();
        model.addAttribute("hospitals", hospitals);
        
        // 生成近五年年度列表
        List<String> years = new ArrayList<>();
        int currentYear = LocalDateTime.now().getYear();
        for (int i = 0; i < 5; i++) {
            years.add(String.valueOf(currentYear - i));
        }
        model.addAttribute("years", years);
        
        return "report-list";
    }
    
    @GetMapping("/api/reports/search")
    @ResponseBody
    public List<Report> searchReports(
            @RequestParam(required = false) String hospitalId,
            @RequestParam(required = false) String year) {
        return reportService.findReports(hospitalId, year);
    }
} 